// pages/share/share.js
var common = require("../../utils/Conmon.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    dataType: '全部分享',
    t: "",
    DB: null,
    nodata:true
  },
  linkToMall: function () {

    wx.switchTab({
      url: '/pages/customIndex/index'
    })
  },
  open: function() {
    let that = this;

    wx.showActionSheet({
      itemList: ['全部分享', '最近7天', '最近15天', '最近一个月'],
      success: function(res) {
        if (!res.cancel) {

          switch (res.tapIndex) {
            case 0:
              that.setData({
                dataType: '全部分享',
                t: ""
              })
              break;
            case 1:
              that.setData({
                dataType: '最近7天',
                t: "near7"
              })
              break;
            case 2:
              that.setData({
                dataType: '最近15天',
                t: "near15"
              })
              break;
            case 3:
              that.setData({
                dataType: '最近一个月',
                t: "near31"
              })
              break;
          }

          that.LoadData();
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    common.pageInit(function() {
      that.LoadData();

    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  cearAll: function() {
    var that = this;
    wx.showModal({
      title: '温馨提示',
      content: '确认清空吗？',
      success: function(res) {
        if (res.confirm) {
        
          var app = getApp();
          var url = app.globalData.apiurl + '/mobile/api/ShareLog/ClearLog';
          var postData = {
            custID: app.globalData.custID,
            userID: wx.getStorageSync('UserInfo').UserID

          }
          wx.request({
            url: url,
            method: "get",
            data: postData,
            header: {
              'X_ManuName': app.globalData.manuName,
            },
            success: res => { //成功
              wx.showToast({
                title: '已清空...',
                duration: 2000
              })
              that.LoadData();
            },
            fail: res => {

            }
          })
        }
      }
    });


  },
  LoadData: function() {
    var that = this;
    var app = getApp();
    var url = app.globalData.apiurl + '/mobile/api/ShareLog/GetShareLogList';
    var postData = {
      custID: app.globalData.custID,
      userID: wx.getStorageSync('UserInfo').UserID,
      type: that.data.t
    }
    wx.request({
      url: url,
      method: "get",
      data: postData,
      header: {
        'X_ManuName': app.globalData.manuName,
      },
      success: res => { //成功
      var hideNodata=true;
        if (res.data.content == null || res.data.content.length == 0)
      {
          hideNodata=false;
      }
        that.setData({
          DB: res.data.content,
          nodata: hideNodata
        })

       
      },
      fail: res => {

      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})